#coding:utf-8
class WifiAccount < ActiveRecord::Base
  has_paper_trail :version => :paper_trail_version, :versions => :paper_trail_versions
  belongs_to :account
  attr_accessible :username, :branch, :password, :used, :used_or_released_at, :account_id, :last_seen, :size
  scope :avaliable, lambda { where('used = false AND used_or_released_at < ? AND accident = false OR used = false AND used_or_released_at < ? AND accident = true OR size > 1', 5.minutes.ago, 10.hours.ago) }

  before_create do
    self.used_or_released_at = Time.now
  end

  def current_status
    if used
      '是'
    elsif accident
      '异常下线'
    else
      '离线'
    end        
  end
end
